package com.pai.servlet;

import com.pai.entity.router.Meta;
import com.pai.entity.router.Router;
import com.pai.vo.ApiResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "routerServlet",urlPatterns = {"/route_list"})
public class RouterServlet extends BaseServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //不在数据库建立路由表，服务器启动之后，此api被访问后，直接手动构建路由列表
        List<Router> routerList = new ArrayList<>();

        //全局的那个路由
        Router router = new Router();
        router.setPath("/");
        router.setComponent("Layout");
        router.setName("myHome");
        Meta meta = new Meta();
        meta.setAlwaysShow(true);
        meta.setHidden(false);
        meta.setIcon("location");
        meta.setRoles(new String[]{"系统管理员", "二级部门管理员", "学生", "辅导员", "学生工作处成员"});
//        meta.setRoles(new String[]{"*"});
        meta.setTitle("没有");
        router.setMeta(meta);

        List<Router> routerIteams = new ArrayList<>();  //子路由集合（这个项目里所有的功能栏都是Layout下的子路由）

        //角色管理
        Router router_1 = new Router();
        router_1.setPath("role");
        router_1.setComponent("system/role/index");
        router_1.setName("role");
        Meta meta_1 = new Meta();
        meta_1.setAlwaysShow(true);
        meta_1.setHidden(false);
        meta_1.setIcon("location");
        meta_1.setRoles(new String[]{"系统管理员"});
        meta_1.setTitle("角色管理");
        router_1.setMeta(meta_1);
        routerIteams.add(router_1);

        //部门管理
        Router router_2 = new Router();
        router_2.setPath("department");
        router_2.setComponent("system/department/index");
        router_2.setName("department");
        Meta meta_2 = new Meta();
        meta_2.setAlwaysShow(true);
        meta_2.setHidden(false);
        meta_2.setIcon("location");
        meta_2.setRoles(new String[]{"系统管理员"});
        meta_2.setTitle("部门管理");
        router_2.setMeta(meta_2);
        routerIteams.add(router_2);

        //行政人员管理
        Router router_3 = new Router();
        router_3.setPath("persAdministrative");
        router_3.setComponent("system/user/persAdministrative");
        router_3.setName("persAdministrative");
        Meta meta_3 = new Meta();
        meta_3.setAlwaysShow(true);
        meta_3.setHidden(false);
        meta_3.setIcon("location");
        meta_3.setRoles(new String[]{"系统管理员"});
        meta_3.setTitle("行政人员管理");
        router_3.setMeta(meta_3);
        routerIteams.add(router_3);

        //部门人员管理（系统管理员版本）
        Router router_4 = new Router();
        router_4.setPath("persDepartmentAll");
        router_4.setComponent("system/user/persDepartmentAll");
        router_4.setName("persDepartmentAll");
        Meta meta_4 = new Meta();
        meta_4.setAlwaysShow(true);
        meta_4.setHidden(false);
        meta_4.setIcon("location");
        meta_4.setRoles(new String[]{"系统管理员"});
        meta_4.setTitle("部门人员管理");
        router_4.setMeta(meta_4);
        routerIteams.add(router_4);

        //部门班级管理（二级学院管理员）
        Router router_5 = new Router();
        router_5.setPath("persDepartmentAll");
        router_5.setComponent("system/department/departmentClass");
        router_5.setName("departmentClass");
        Meta meta_5 = new Meta();
        meta_5.setAlwaysShow(true);
        meta_5.setHidden(false);
        meta_5.setIcon("location");
        meta_5.setRoles(new String[]{"二级部门管理员"});
        meta_5.setTitle("班级管理");
        router_5.setMeta(meta_5);
        routerIteams.add(router_5);

        //学生管理（二级学院管理员）
        Router router_6 = new Router();
        router_6.setPath("persStudent");
        router_6.setComponent("system/user/persStudent");
        router_6.setName("persStudent");
        Meta meta_6 = new Meta();
        meta_6.setAlwaysShow(true);
        meta_6.setHidden(false);
        meta_6.setIcon("location");
        meta_6.setRoles(new String[]{"二级部门管理员"});
        meta_6.setTitle("学生管理");
        router_6.setMeta(meta_6);
        routerIteams.add(router_6);

        //辅导员管理（二级学院管理员）
        Router router_7 = new Router();
        router_7.setPath("persCounselor");
        router_7.setComponent("system/user/persCounselor");
        router_7.setName("persCounselor");
        Meta meta_7 = new Meta();
        meta_7.setAlwaysShow(true);
        meta_7.setHidden(false);
        meta_7.setIcon("location");
        meta_7.setRoles(new String[]{"二级部门管理员"});
        meta_7.setTitle("辅导员管理");
        router_7.setMeta(meta_7);
        routerIteams.add(router_7);

        //创建请假单（学生）
        Router router_8 = new Router();
        router_8.setPath("leaveTicketStu");
        router_8.setComponent("leave/leaveTicketStu");
        router_8.setName("leaveTicketStu");
        Meta meta_8 = new Meta();
        meta_8.setAlwaysShow(true);
        meta_8.setHidden(false);
        meta_8.setIcon("location");
        meta_8.setRoles(new String[]{"学生"});
        meta_8.setTitle("创建假条");
        router_8.setMeta(meta_8);
        routerIteams.add(router_8);

        //审核请假单（老师）
        Router router_9 = new Router();
        router_9.setPath("leaveTicketCol");
        router_9.setComponent("leave/leaveTicketCol");
        router_9.setName("leaveTicketCol");
        Meta meta_9 = new Meta();
        meta_9.setAlwaysShow(true);
        meta_9.setHidden(false);
        meta_9.setIcon("location");
        meta_9.setRoles(new String[]{"辅导员"});
        meta_9.setTitle("审批假条");
        router_9.setMeta(meta_9);
        routerIteams.add(router_9);

        //查看学生信息（老师）
        Router router_10 = new Router();
        router_10.setPath("persStudentCol");
        router_10.setComponent("system/user/persStudentCol");
        router_10.setName("persStudentCol");
        Meta meta_10 = new Meta();
        meta_10.setAlwaysShow(true);
        meta_10.setHidden(false);
        meta_10.setIcon("location");
        meta_10.setRoles(new String[]{"辅导员"});
        meta_10.setTitle("查看学生信息");
        router_10.setMeta(meta_10);
        routerIteams.add(router_10);

        //请假单数据统计（学工处人员、二级管理员、辅导员）
        Router router_11 = new Router();
        router_11.setPath("statisticsLeave");
        router_11.setComponent("statistics/statisticsLeave");
        router_11.setName("statisticsLeave");
        Meta meta_11 = new Meta();
        meta_11.setAlwaysShow(true);
        meta_11.setHidden(false);
        meta_11.setIcon("location");
        meta_11.setRoles(new String[]{"二级部门管理员", "学生工作处成员", "辅导员"});
        meta_11.setTitle("请假统计");
        router_11.setMeta(meta_11);
        routerIteams.add(router_11);


        router.setChildren(routerIteams);

        routerList.add(router);

        ApiResult apiResult = new ApiResult();
        apiResult.setData(routerList);

        super.write(resp, apiResult);



    }
}
